var arr = [12,3,5,2,9,10,1]
// arr = [1, 3, 5, 2, 9, 10, 12]
console.log(arr)
var cnt = 1;
sort(0, arr.length - 1, arr)


console.log("final > ", arr)

function sort(left, right, arr){
	if(left > right){
		console.log("%s > %s return", left, right);
		return;
	}
		
	var left_point = left;
	var right_point = right;

	var poiv = arr[left];

	while(left_point !== right_point){
		console.log("while left_point > %s, right_point > %s", left_point, right_point)
		// from right 
		while(arr[right_point] >= poiv && left_point < right_point && right_point > 0){
			console.log("			rp--", right_point)
			right_point--;
		}

		console.log("	right_point >", right_point)

		while(arr[left_point] <= poiv && left_point < right_point){
			
			left_point++;
			(function(i){
				console.log("		lp++", i);
			})(left_point);
		}

		console.log("	left_point >", left_point)


		if(left_point < right_point) {
			console.log("	change point > %s <> %s", arr[left_point], arr[right_point]);
			var tmp = arr[left_point];
			arr[left_point] = arr[right_point];
			arr[right_point] = tmp;
			console.log("	arr > ", arr);
		}
		
	}

	
	
	if(arr[left_point] !== poiv) {
		console.log("	change povi > %s <> %s", arr[left_point], poiv);
		arr[left] = arr[left_point];
		arr[left_point] = poiv;
		console.log("	arr > ", arr);
	}
	

	console.log("	left_point > %s, right_point > %s | left > %s, right > %s", 
		left_point, right_point, left, right)
	sort(left, left_point - 1, arr)
	sort(left_point + 1, right, arr)



	
}